package net.pingfang.devicelock.Config;

import lombok.extern.slf4j.Slf4j;
import net.pingfang.devicelock.Decoder.Type0200Decoder;
import net.pingfang.devicelock.Decoder.Type0311Decoder;
import net.pingfang.devicelock.Decoder.Type0313Decoder;
import net.pingfang.devicelock.common.CommonConstant;
import net.pingfang.devicelock.constant.PacketDecoder;
import net.pingfang.devicelock.Decoder.Type0219Decoder;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Component
public class DecoderFactory {

    private static final ConcurrentHashMap<String, PacketDecoder<?>> decoders = new ConcurrentHashMap<>();

    public DecoderFactory(){
        /*
          注册默认解码器
          1.当前位置返回32, 48, 50, 32
          2.终端参数设置应答 48, 51, 49, 49
          3.终端参数查询应答 48, 51, 49, 51
          4.向设备写入业务数据应答 48, 50, 49, 57
         */
        decoders.put("0200", new Type0200Decoder(CommonConstant.sessions));
        decoders.put("0313", new Type0313Decoder(CommonConstant.sessions));
        decoders.put("0311", new Type0311Decoder(CommonConstant.sessions));
        decoders.put("0219", new Type0219Decoder(CommonConstant.sessions));
    }

//    public void registerDecoder(String str, PacketDecoder<?> decoder) {
//        decoders.put(str, decoder);
//    }

    public PacketDecoder<?> getDecoder(String type) {
        return decoders.get(type);
    }
}
